package com.algorithm;

import java.util.HashMap;

/**
 * @author: sun.hongliang
 * @create: 2019/11/15 11:13
 */
public class RotateTest {
    public static void main(String[] args) {
        HashMap<String, Object> map = new HashMap<>(2);
        map.put(null, null);
    }

    public void rotate(int[] nums, int k) {
        int len = k % nums.length;
        reverse(nums, 0, nums.length - 1 - len);
        reverse(nums, nums.length - len, nums.length - 1);
        reverse(nums, 0, nums.length - 1);
    }


    private void reverse(int[] nums, int start, int end) {
        while (start < end) {
            int temp = nums[start];
            nums[start] = nums[end];
            nums[end] = temp;
            start++;
            end--;
        }
    }

}
